//客户端引入mqtt
let mqtt = require('mqtt');

let client = mqtt.connect('mqtt://localhost', {
    port: 1883,
    clientId: 'cli_pub',
    username: '123',
    password: 'rt:02fea06ace68595d42a4a30568e447074114c3e5',
    clean: false//增加了此项
})

let num = 0;
setInterval(function () {
    var data = {
        id: num++,
        title: '标题' + num,
        body: '内容' + num,
        payload: '请求体' + num
    }
    client.publish('system/123',
        JSON.stringify(data),
        { qos: 1 },
        () => console.log(num));
}, 10000)